// 导出defineConfig方法可以让编辑器（VSCode）智能提示所有的rollup的配置项，很方便
import { defineConfig } from 'rollup'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import dts from 'rollup-plugin-dts'
import esbuild from 'rollup-plugin-esbuild'

// 引入package.json
import pkg from './package.json'

// 拿到package.json的name属性来动态设置打包名称
const libName = pkg.name

const bundle = config => ({
	...config,
	input: 'src/index.ts'
})

export default defineConfig([
	bundle({
		plugins: [esbuild({ target: 'es2015' }), nodeResolve()],
		output: [
			{
				file: `dist/index.js`,
				format: 'cjs',
				sourcemap: true
			},
			{
				file: `dist/index.es.js`,
				format: 'es',
				sourcemap: true
			}
		]
	}),
	bundle({
		plugins: [dts()],
		output: {
			file: 'dist/index.d.ts',
			format: 'es'
		}
	})
])
